<#include "/public/macro.html">
<div class="uk-layui-form" style="height: calc(100% - 50px);padding-top:0px;">
	<form class="layui-form" action="/apps/workorders/embed/save.html" method="post" style="width: 100%;height: 100%;" data-toggle="ajax-form" data-inner="#workorders"  enctype="multipart/form-data">
		<#if contacts??><input type="hidden" name="contactsid" value="${contacts.id!''}"/></#if>
		<#if source??><input type="hidden" name="source" value="${source!''}"/></#if>
		<#if dataid??><input type="hidden" name="dataid" value="${dataid!''}"/></#if>
		<#if eventid??><input type="hidden" name="eventid" value="${eventid!''}"/></#if>
		<div class="ukefu-containter">
			<div class="ukefu-col-left">
				<h1 class="site-h1">
					工单基本信息
				</h1>
				<#if models?? && models["contacts"]?? && models["contacts"] == true>
				<#if contacts??>
				<div class="layui-form-item ukefu-form-item">
					<label class="layui-form-label ukefu-form-label">
						联系人
						<font color="red">*（必填项）</font>
					</label>
					<div class="layui-input-block">
						<select id="contacts" name="cusid" lay-ignore class="layui-input layui-unselect" style="width: 100%">
						  	<#if contacts??><option value="${contacts.id!''}" selecte="selected">${contacts.name!''}</option></#if>
						</select>
					</div>
				</div>
				<#else>
				<div class="layui-form-item ukefu-form-item">
					<label class="layui-form-label ukefu-form-label">
						联系人姓名
						<font color="red">*（必填项）</font>
					</label>
					<div class="layui-input-block">
						<input type="text" name="name" autocomplete="off" class="layui-input" required lay-verify="required">
					</div>
				</div>
				<div class="layui-form-item ukefu-form-item">
					<label class="layui-form-label ukefu-form-label">
						联系人电话
					</label>
					<div class="layui-input-block">
						<input type="text" name="ani" autocomplete="off" class="layui-input"  value="${ani!''}">
					</div>
				</div>
				</#if>
				</#if>

				<div class="layui-form-item ukefu-form-item">
					<label class="layui-form-label ukefu-form-label">
						所属单位
					</label>
					<div class="layui-input-block">
						<input type="text" name="cusorgan" autocomplete="off" class="layui-input" value="${organ!''}">
					</div>
				</div>


				<div class="layui-form-item ukefu-form-item">
					<label class="layui-form-label ukefu-form-label">
						工单发起人
					</label>
					<div class="layui-input-block">
						<select id="initiator" name="initiator" lay-ignore class="layui-input layui-unselect" style="width: 100%">
							<option value="${user.id!''}">${user.username!''}</option>
						 	<#if userList?? && userList.content??>
						 	<#list userList.content as wouser>
						 	<#if wouser.id != user.id>
						 	<option value="${wouser.id!''}">${wouser.username!''}（${wouser.uname!''}）</option>
						 	</#if>
						 	</#list>
						 	</#if> 
						</select>
					</div>
				</div>
				<div class="layui-inline ukefu-form-item">
					<label class="layui-form-label ukefu-form-label">受理部门/受理人</label>
					<div class="layui-input-inline" style="width: 145px;">
						<select lay-ignore class="ukefu-select" name="accdept" id="accdept" style="width: 100%">
							<option value="">请选择部门</option>
						 	<#if organList??>
						 	<#list organList as organ>
						 	<option value="${organ.id!''}">${organ.name!''}</option>
						 	</#list>
						 	</#if> 
						</select>
					</div>
					<div class="layui-input-inline" style="width: 145px;" id="deptuserdiv">
						<#include "/apps/business/workorders/deptuser.html">
					</div>
				</div>
				
				<div class="layui-form-item ukefu-form-item">
					<label class="layui-form-label ukefu-form-label">工单状态</label>
					<div class="layui-input-block">
						<select id="status" name="status" lay-ignore="" class="ukefu-select select2-hidden-accessible" style="width:100%;"  tabindex="-1" aria-hidden="true">
							<#list uKeFuDic['com.dic.workorders.status'] as macroSysDic>
							<#if macroSysDic.name=='未受理'>
							<option value="<#if macroSysDic.discode>${macroSysDic.code}<#else>${macroSysDic.id}</#if>">${macroSysDic.name}</option>
							</#if>
							</#list>
						</select>
					</div>
				</div>
				
				<div class="layui-form-item ukefu-form-item">
					<label class="layui-form-label ukefu-form-label">工单类型</label>
					<div class="layui-input-block">
						<select name="wotype" lay-ignore class="ukefu-select" style="width:100%;" id="wotype">
							<#if workOrderTypeList?? && workOrderTypeList?size gt 0>
							<#list workOrderTypeList as workOrderType>
								<option value="${workOrderType.id!''}">${workOrderType.name!''}<#if workOrderType.bpm>（流程）</#if></option>
							</#list>
							</#if>
						</select> 
					</div>
				</div>
				
				<div class="layui-form-item ukefu-form-item">
					<label class="layui-form-label ukefu-form-label">优先级</label>
					<div class="layui-input-block">
						<@select "com.dic.workorders.priority" "priority" "" "lay-ignore class=ukefu-select style=width:100%;"/>
					</div>
				</div>
				
				<div class="layui-form-item ukefu-form-item">
					<label class="layui-form-label ukefu-form-label">标签</label>
					<div class="layui-input-block">
						<select lay-ignore name="tags" class="ukefu-select" style="width: 100%" id="tags">
						 	<#if tags?? && tags?size gt 0>
						 	<#list tags as tag>
						 	<option value="${tag.id!''}">${tag.tag!''}</option>
						 	</#list>
						 	</#if> 
						</select>
					</div>
				</div>
			</div>
			<div class="ukefu-col-right">
				<h1 class="site-h1">
					工单内容
				</h1>
				<div class="layui-form-item">
					<label class="layui-form-label">工单标题
						<font color="red">*</font>
					</label>
					<div class="layui-input-block ukefu-form-block">
						<input type="text" name="title" autocomplete="off" class="layui-input" required lay-verify="required">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">
						工单内容
						<font color="red">*</font>
					</label>
					<div class="layui-input-block ukefu-form-block">
						<textarea name="content" id="content" style="width:100%;height:260px;">
						<#if messageList?? && messageList.content??>
                                <#list messageList.content?reverse as chatmessage>
                                    <div class="clearfix chat-block">
                                        <div class="<#if (chatmessage.userid?? && chatmessage.userid == user.id) || (chatmessage.calltype?? && chatmessage.calltype == 'out')>chat-right<#else>chat-left</#if>">
                                            <img alt="" src="<#if chatmessage.userid?? && chatmessage.userid == user.id>/images/im/user.png<#else><#if curagentuser.headimgurl?? && curagentuser.headimgurl !=''>${curagentuser.headimgurl}<#else>/images/im/user.png</#if></#if>" style="width:45px;height:45px;" class="user-img">
                                            <div class="chat-message">
                                                <span class="user">${chatmessage.username!''}</span>
                                                <span class="time">${chatmessage.createtime!''}</span></div>
                                            <div class="<#if (chatmessage.userid?? && chatmessage.userid == user.id) || (chatmessage.calltype?? && chatmessage.calltype == 'out')>chatting-right<#else>chatting-left</#if>">
                                                <i class="userarrow"></i>
                                                <div class="chat-content"><#include "/apps/agent/media/message.html"></div>
                                            </div>
                                        </div>
                                    </div>
                                </#list>
						</#if></textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">
						附件
					</label>
					<div class="layui-input-block ukefu-form-block">
						<div class="layui-box layui-upload-button">
							<input type="file" name="files"
								accept="*"
								class="layui-upload-file"
								onchange="$(this).closest('.layui-form-item').append($(this).closest('.ukefu-form-block').prop('outerHTML'));$(this).closest('.ukefu-form-block').find('.file_ad').html($(this).val());$(this).closest('.ukefu-form-block').find('.file_del').show();"><span
								class="layui-upload-icon"><i class="layui-icon">&#xe608;</i>上传附件</span>
						</div>
						<span>
							<span class="file_ad"></span>
							<span class="file_del" style="display:none;">
								<a href="javascript:void(0)" style="margin-left:10px;" onclick="$(this).closest('.ukefu-form-block').remove();">
						  			<i class="layui-icon" style="color:red;">&#x1006;</i>
						  			删除
						  		</a>
							</span>
						</span>
					</div>
				</div>
			</div>
		</div>

		<div class="layui-form-button">
			<div class="layui-button-block">
				<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
</div>

<script>
	$(function(){
		if(${workOrderTypeList?size} <= 0){
			$("#wotype").attr("disabled","true");
		}
		if(${tags?size} <= 0){
			$("#tags").attr("disabled","true");
		}
	});
	layui.use('form', function() {
		var form = layui.form;
		form.render(); //更新全部
	});
	layui.use('element', function(){
		var element = layui.element;
	});
	KindEditor.create('#content', {
		themeType : 'simple',
		width:"100%",
		resizeType:0,
		zIndex:123456789,
		uploadJson : "/res/image/upload.html",
		items : ['fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
				 'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
				 'insertunorderedlist', '|', 'emoticons', 'image', 'link'],
		htmlTags: {div : ['class', 'style'],li:['style'],img:['src','alt','style','class'],span:['class','style'],i:['style','class'],ul:['class','style']}  ,
        allowFileManager : false,
		fontsize:16
	});
	KindEditor.options.cssData = "body { font-size: 15px; font-family:'Microsoft Yahei', 'Helvetica', 'Simsun', 'Arial';}.chat-left{	display: inline-block;	width:100%;}.chat-right{	display: inline-block;	width:100%;}.chat-left .user-img{	float: left;	margin-top: 6px;    border-radius: 50%;}.chat-left .chat-message{	display:block;	margin-left:60px;    text-align: left;}.chat-left .chat-message .user{	color:#4665d4;    font-weight: 400;    float:left;}.chat-left .chat-message .time{	color:#aaaaaa;	margin-left:5px;}.chat-right .user-img{	float:right;	margin-top: 6px;    border-radius: 50%;}.chat-right .chat-message{	display:block;	margin-right:60px;    text-align: right;}.chat-right .chat-message .user{	color:#4665d4;    font-weight: 400;    float:right;}.chat-right .chat-message .time{	color:#aaaaaa;	margin-right:5px;}.chatting-left{	display:block;	margin-left: 60px;	position: relative;}.chatting-right{	display:block;	margin-right: 60px;	position: relative;}.chatting-left .userarrow {    position: absolute;    height: 0;    font-size: 0;    border: 6px solid #dddddd;    top: -4px;    left: 16px;    border-color: #ffffff #ffffff #dddddd;}.chatting-right .userarrow{	position: absolute;    height: 0;    font-size: 0;    border: 6px solid #eef0f0;    top: -4px;    right: 16px;    border-color: #ffffff #ffffff #c7dcfa;}.chatting-left div.chat-content {    border-radius: 3px;    padding: 4px;    margin-bottom: 0;    padding-right: 5px;    padding-left: 5px;    margin-top: 8px;        background-color: #EDEDED !important;    border: 1px solid #DDDDDD;    float: left;    min-width: 25px;    word-break: break-all;}.chatting-left div.chat-content *{	background-color: #EDEDED !important;}.chatting-right div.chat-content *{	background-color: #c7dcfa !important;}.chatting-left div.chat-content a{    color:#4665d4;    text-decoration: none;}.chatting-right div.chat-content{	border-radius: 3px;	padding:4px;	margin-bottom: 0;	padding-right: 5px;	padding-left:5px;    margin-top: 8px;	    max-width: calc(100% - 75px);	background-color: #c7dcfa;	border: 1px solid #b2e5f9;    float: right;    min-width: 25px;    word-break: break-all;}.chatting-right div.chat-content a{    color:#4665d4;    text-decoration: none;}.chatting-left div.chat-content span{	color: #000000;	font-size: 13px;}.chat-block {    margin-top: 10px;    padding: 10px;}.chat-block .connect-message {    border-radius: 3px;    color: #fff;    display: inline-block;    font-size: 15px;    padding: 3px 6px;    text-align: left;}.workorder-chat-left .workorder-suggest-item,.workorder-chat-right .workorder-suggest-item {    font-size: 14px;    padding: 0 0 11px 18px;    color: rgba(35, 39, 50, 0.8);    background: url(/images/circle.png) no-repeat left 8px;}.info-list .workorder-suggest-item {    font-size: 14px;    padding: 0 0 11px 18px;    color: rgba(35, 39, 50, 0.8);    background: url(/images/circle.png) no-repeat left 8px;}";
	$(document).ready(function() {
		$("#contacts").select2({
			language: 'zh-CN' ,
			placeholder: "请选择发起人",
			ajax: {
				url: "/res/contacts.html",
				dataType: 'json',
				delay: 250,
				processResults: function (data, params) {
					return {
						results: data
					};
				}    
			}
		});
		
		$("#initiator").select2({
			language: 'zh-CN' ,
			placeholder: "请选择发起人",
			ajax: {
				url: "/res/users.html",
				dataType: 'json',
				delay: 250,
				processResults: function (data, params) {
					return {
						results: data
					};
				}    
			}
		});
		
		$(".ukefu-select").select2({minimumResultsForSearch: Infinity});
		$('#accdept').on('select2:select', function (evt) {
			 //选择部门下的 人员
			 loadURL("/apps/workorders/dept/user.html?dept="+evt.target.value , "#deptuserdiv");
		});
	});
</script>